package cn.mini.mybatis.session.defaults;

import cn.mini.mybatis.mapping.MappedStatement;
import cn.mini.mybatis.session.Configuration;
import cn.mini.mybatis.session.SqlSession;
import lombok.extern.slf4j.Slf4j;



@Slf4j
public class DefaultSqlSession implements SqlSession {

    private Configuration configuration;

    public DefaultSqlSession(Configuration configuration) {
        this.configuration = configuration;
    }



    @Override
    public <E> E selectOne(String statement, Object parameter) {
        MappedStatement mappedStatement = configuration.getMappedStatement(statement);
        log.info("使用 MappedStatement, 待执行sql: {}", mappedStatement.getSql());
        log.info("模拟数据库查询操作........");
        return null;
    }

    @Override
    public <T> T getMapper(Class<T> type) {
        // 使用 Java 的动态代理生成 Mapper 接口的代理对象
        return configuration.getMapper(type,this);
    }
}
